//
//  NMPONavView.swift
//  NMPO
//
//  Created by PowerfullClean on 2023/10/31.
//

import UIKit

class NMPONavView: UIView {
    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 0, width: nmpo_SCREEN_WIDTH, height: NMPOCommon.nmpo_navHegiht))
        nmpo_initViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func nmpo_initViews()  {
        addSubview(nmpo_leftButton)
        addSubview(nmpo_titleLabel)
        
        nmpo_leftButton.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-26)
            make.left.equalToSuperview().offset(20)
            make.size.equalTo(24)
        }
        nmpo_titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(nmpo_leftButton.snp.centerY)
            make.centerX.equalToSuperview()
        }
    }
    
    @objc func nmpo_buttonClick(sender: UIButton) {
        if sender == nmpo_leftButton {
            if (nmpo_leftBlock != nil) {
                nmpo_leftBlock?()
                return
            }
            nmpo_viewGetVController?.navigationController?.popViewController(animated: true)
            return
        }
    }
    
    var nmpo_leftBlock:(()->())?
    
    lazy var nmpo_leftButton: UIButton = {
        let nmpo_leftButton = UIButton()
        nmpo_leftButton.setImage(UIImage(named: "nmpo_nav_back"), for: .normal)
        nmpo_leftButton.addTarget(self, action: #selector(nmpo_buttonClick(sender:)), for: .touchUpInside)
        return nmpo_leftButton
    }()
    
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 18)
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        return nmpo_titleLabel
    }()
    
}

